home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / GroupsPaneModel.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  8KB  |  211 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gobject
  5. import gtk
  6. import libxml2
  7. from XmlHelper import xml_helper
  8. from SearchCriterion import *
  9. from gettext import gettext as _
  10. from debug import *
  11.  
  12. class GroupsPaneItem(gobject.GObject):
  13.     
  14.     def __init__(self):
  15.         super(GroupsPaneItem, self).__init__()
  16.         self.icon = None
  17.         self.name = None
  18.         self.separator = False
  19.  
  20.     
  21.     def load_icon(self, icon_name):
  22.         theme = gtk.icon_theme_get_default()
  23.         
  24.         try:
  25.             return theme.load_icon(icon_name, gtk.ICON_SIZE_MENU, 0)
  26.         except gobject.GError:
  27.             return None
  28.  
  29.  
  30.  
  31.  
  32. class AllPrintersItem(GroupsPaneItem):
  33.     
  34.     def __init__(self):
  35.         super(AllPrintersItem, self).__init__()
  36.         self.icon = self.load_icon('printer')
  37.         self.name = _('All Printers')
  38.  
  39.  
  40.  
  41. class SeparatorItem(GroupsPaneItem):
  42.     
  43.     def __init__(self):
  44.         super(SeparatorItem, self).__init__()
  45.         self.separator = True
  46.  
  47.  
  48.  
  49. class FavouritesItem(GroupsPaneItem):
  50.     
  51.     def __init__(self):
  52.         super(FavouritesItem, self).__init__()
  53.         self.icon = self.load_icon('emblem-favorite')
  54.         self.name = _('Favorites')
  55.  
  56.  
  57.  
  58. class MutableItem(GroupsPaneItem):
  59.     
  60.     def __init__(self, name, xml_node = None):
  61.         super(MutableItem, self).__init__()
  62.         self.name = name
  63.         self.xml_node = xml_node
  64.  
  65.     
  66.     def rename(self, new_name):
  67.         self.xml_node.setProp('name', new_name)
  68.         xml_helper.write()
  69.         self.name = new_name
  70.  
  71.     
  72.     def delete(self):
  73.         self.xml_node.unlinkNode()
  74.         self.xml_node.freeNode()
  75.         xml_helper.write()
  76.  
  77.  
  78.  
  79. class StaticGroupItem(MutableItem):
  80.     
  81.     def __init__(self, name, xml_node = None):
  82.         super(StaticGroupItem, self).__init__(name, xml_node)
  83.         self.icon = self.load_icon('folder')
  84.         self.printer_queues = []
  85.         if not self.xml_node:
  86.             self.xml_node = libxml2.newNode('static-group')
  87.             self.xml_node.newProp('name', self.name)
  88.             self.xml_node.newChild(None, 'queues', None)
  89.             xml_helper.add_group(self.xml_node)
  90.         elif not self.xml_node.children.children:
  91.             return None
  92.         queue_node = self.xml_node.children.children
  93.         while queue_node:
  94.             self.printer_queues.append(queue_node.prop('name'))
  95.             queue_node = queue_node.next
  96.  
  97.     
  98.     def add_queues(self, queue_list):
  99.         queues_node = self.xml_node.children
  100.         for queue_name in queue_list:
  101.             if queue_name not in self.printer_queues:
  102.                 queue_node = libxml2.newNode('queue')
  103.                 queue_node.newProp('name', queue_name)
  104.                 queues_node.addChild(queue_node)
  105.                 self.printer_queues.append(queue_name)
  106.                 continue
  107.         
  108.         xml_helper.write()
  109.  
  110.     
  111.     def remove_queues(self, queue_list):
  112.         queues_node = self.xml_node.children
  113.         for queue_name in queue_list:
  114.             if queue_name in self.printer_queues:
  115.                 queue_node = self.xml_node.children.children
  116.                 while queue_node:
  117.                     if queue_node.prop('name') == queue_name:
  118.                         break
  119.                     
  120.                     queue_node = queue_node.next
  121.                 queue_node.unlinkNode()
  122.                 queue_node.freeNode()
  123.                 self.printer_queues.remove(queue_name)
  124.                 continue
  125.         
  126.         xml_helper.write()
  127.  
  128.  
  129.  
  130. class SavedSearchGroupItem(MutableItem):
  131.     
  132.     def __init__(self, name, criteria = [], match_all = False, xml_node = None):
  133.         super(SavedSearchGroupItem, self).__init__(name, xml_node)
  134.         self.icon = self.load_icon('folder-saved-search')
  135.         self.criteria = criteria
  136.         self.match_all = match_all
  137.         if not self.xml_node:
  138.             self.xml_node = libxml2.newNode('search-group')
  139.             self.xml_node.newProp('name', self.name)
  140.             criteria_node = self.xml_node.newChild(None, 'criterias', None)
  141.             if not self.match_all or 'all':
  142.                 pass
  143.             criteria_node.newProp('match', 'any')
  144.             for criterion in self.criteria:
  145.                 criterion_node = criteria_node.newChild(None, 'criteria', None)
  146.                 criterion_node.newChild(None, 'subject', str(criterion.subject))
  147.                 criterion_node.newChild(None, 'rule', str(criterion.rule))
  148.                 criterion_node.newChild(None, 'value', str(criterion.value))
  149.             
  150.             xml_helper.add_group(self.xml_node)
  151.         else:
  152.             criteria_node = self.xml_node.children
  153.             self.match_all = criteria_node.prop('match') == 'all'
  154.             criterion_node = criteria_node.children
  155.             while criterion_node:
  156.                 criterion = SearchCriterion()
  157.                 crit_child = criterion_node.children
  158.                 while crit_child:
  159.                     if crit_child.name == 'subject':
  160.                         criterion.subject = int(crit_child.content)
  161.                     elif crit_child.name == 'rule':
  162.                         criterion.rule = int(crit_child.content)
  163.                     elif crit_child.name == 'value':
  164.                         criterion.value = crit_child.content
  165.                     
  166.                     crit_child = crit_child.next
  167.                 self.criteria.append(criterion)
  168.                 criterion_node = criterion_node.next
  169.  
  170.  
  171.  
  172. class GroupsPaneModel(gtk.ListStore):
  173.     
  174.     def __init__(self):
  175.         super(GroupsPaneModel, self).__init__(GroupsPaneItem)
  176.  
  177.     
  178.     def append(self, item):
  179.         return super(GroupsPaneModel, self).append([
  180.             item])
  181.  
  182.     
  183.     def get(self, iter_or_path):
  184.         return self[iter_or_path][0]
  185.  
  186.     
  187.     def lookup_by_name(self, name):
  188.         for item in self:
  189.             if name == item[0].name:
  190.                 return item[0]
  191.         
  192.  
  193.     
  194.     def append_by_type(self, new_item):
  195.         new_item_type = type(new_item)
  196.         titer = self.get_iter_first()
  197.         while titer:
  198.             if type(self.get_value(titer, 0)) == new_item_type:
  199.                 break
  200.             
  201.             titer = self.iter_next(titer)
  202.         while titer:
  203.             if type(self.get_value(titer, 0)) != new_item_type:
  204.                 break
  205.             
  206.             titer = self.iter_next(titer)
  207.         return self.insert_before(titer, [
  208.             new_item])
  209.  
  210.  
  211.